package com.xander.qqdatabase.service.impl;

import com.xander.qqdatabase.entity.Group;
import com.xander.qqdatabase.enums.ErrorCodeEnum;
import com.xander.qqdatabase.mapper.GroupMapper;
import com.xander.qqdatabase.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.xander.qqdatabase.util.CheckUtil.check;

/**
 * @author 叶振东
 * @date 2019-01-23
 */
@Service
public class GroupServiceImpl implements GroupService {
    @Autowired
    private GroupMapper groupMapper;

    @Value("${system.allowOwner}")
    private Boolean allowUser;

    @Override
    public List<Group> getByQQ(Integer qqNum) {
        check(qqNum!=null, ErrorCodeEnum.PARAMETER_EMPTY,"","");
        if(!allowUser) {
            check(!qqNum.equals(315695355), ErrorCodeEnum.NOT_ALLOW_NUMBER,"","");
        }
        return groupMapper.getByQQ(qqNum);
    }

    @Override
    public List<Group> getByQun(Integer qun) {
        check(qun!=null, ErrorCodeEnum.PARAMETER_EMPTY,"","");
        return groupMapper.getByQun(qun);
    }
}
